var ctx=window.daijia.ctx;


$(document).ready(function(){
	
	$("#startTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
	$("#endTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
	
	$('#companyId').multiselect({
		enableFiltering: true,
	    includeSelectAllOption: true,
	    selectAllText: '全部',
	    selectAllJustVisible: true,
	    maxHeight:300,
	    buttonWidth: '100%',
	    nonSelectedText: '请选择所属公司',
	    nSelectedText: ' - 已选择',
	    numberDisplayed: 4,
	    allSelectedText: '已选择全部'
	});
	
	
	KindEditor.ready(function(K) {
		K.create('#contentMore',{
			filterMode : false,
			uploadJson : ctx+'/common/kindeditor/fileupload',
			allowUpload : true,
			fileManagerJson : ctx+'/common/kindeditor/filemanager',
			allowFileManager : true,
			height:400,
			width:'100%',
			resizeType:0,
			afterCreate : function() {
				var self = this;
				K.ctrl(document, 13, function() {
					self.sync();
				});
				K.ctrl(self.edit.doc, 13, function() {
					self.sync();
				});
			},
			afterBlur:function(){ 
				this.sync();
			}
		});
	});
	
	$("input[name=writemore]").change(function(){
		if(!$(this).prop("checked")){
			$("#contentMore_div").hide();
			
		}
		else{
			$("#contentMore_div").slideDown();
			
		}
	});
	
	$("input[name=sendType]").change(function(){
		if($(this).val()=="sms"){
			if($(this).is(':checked')){
				$("#sendType_sms_info").show();
			}
			else{
				$("#sendType_sms_info").hide();
			}
		}
	});
	
	
	$("#content").keyup(function(){
		$("#putWords").html($(this).val().length);
	});
	
	$("#submit_form").submit(function(){
		if($("#content").val()=="" || $("#content").val().trim()=="" || $("#content").val().trim()==null){
			$.scojs_message("请填写通知内容", $.scojs_message.TYPE_ERROR);
			return false;
		}
		
		if($("input[name=sendType]:checked").length==0){
			$.scojs_message("请选择发送方式", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if(window.confirm('确认条件并发布吗？')){
			$("#submit_button").attr("disabled",true);
			
			$.post(ctx+'/notice/create',$("#submit_form").serialize(),function(result){
				if(result.success){
					window.location=ctx+"/notice/list";
				}
				else{
					$.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
					$("#submit_button").attr("disabled",false);
				}
			});
		}
		
		return false;
	});
	
});

